<template>
    <view>
        <image :src="imgsd" class="kjknkkjsd w100 cz" mode="aspectFit"></image>
		<view class="mt20 pl100 row">
			<view class="jkjhnnjserr cen" @tap="chnjhghgas(0)">
				<image src="../../static/img/xiangce.png" class="xianggeert"></image>
				<view class="cf fz28">
					相册
				</view>
			</view>
			<view class="col kjjnnjeert">
				<view class="paizainxnseetr" @tap="chnjhghgas(1)">
					
				</view>
			</view>
		</view>
    
	
	</view>
</template>
<script>
    export default {
        data() {
            return {
				imgsd:'../../static/img/paizao.png',
				carform:{},
				cardata:''
			}
        },
        components: {},
		onNavigationBarButtonTap(e) {		
			console.log(this.carform)
			if(!this.carform.hasOwnProperty('image')){
				uni.showToast({
					title:"请选择车库图片",
					icon:"none"
				})
				return
			}
			if(this.carform.image.length == 0){
				uni.showToast({
					title:"请选择车库图片",
					icon:"none"
				})
				return
			}
			var carform = JSON.stringify(this.carform)
			// uni.setStorageSync('carform',this.carform)
			uni.navigateTo({
				url:'SetName?data='+carform
			})
		},
        methods: {			
			chnjhghgas(type){
				var hbvsd = [],
				th=this
				if (type==0){ // 相册
					hbvsd= ['album']
				} else if(type == 1){ // 拍照
					hbvsd= ['camera']
				}
				let token = uni.getStorageSync('access_token')
				uni.chooseImage({
				    count: 1, //默认9
				    sourceType: hbvsd, //从相册选择
				    success: function (res) {
						console.log("图片",res.tempFiles[0].name)
						// th.imgsd = res.tempFilePaths[0]						
						uni.uploadFile({
							url: 'http://kenide.youfai.cn/api/images', //仅为示例，非真实的接口地址
							filePath: res.tempFilePaths[0],
							name: 'file',
							header:{
								Accept:'application/json',
								Authorization:token
							},
							formData: {
								// 'image': res.tempFiles[0].name,
								'type':'image'
							},
							success: (uploadFileRes) => {
								let uploads=JSON.parse(uploadFileRes.data)
								console.log(uploads);
								th.imgsd=uploads.data.path
								th.carform.image=uploads.data.id
							}
						});
				    }
				});
			}
		},
        mounted() {},
		onLoad(options) {
			// var data=JSON.parse(options.data)
			// console.log(5555)
			// console.log(a)
			// uni.$on("carform", (data) => {
			// 	console.log("接收事件test成功,data=", data);
			// })
			this.carform = JSON.parse(options.data)
			// this.carform=uni.getStorageSync('carform')
			// console.log("1111111111111111111111111")
			// console.log(options.data)
			// console.log(JSON.parse(options.data))
			// console.log(this.carform)
			// console.log("接受数据1",this.carform)
		}
    }

</script>
<style  scoped>
	.kjknkkjsd{
		height: 1000upx;
	}
	.jkjhnnjserr{
		width: 92upx;
	}
	.xianggeert{
		width: 92upx;
		height: 92upx;
	}
	.kjjnnjeert{
		margin-left: 110upx;
	}
	.paizainxnseetr{
		width: 152upx;
		height: 152upx;
		border-radius: 50%;
		border: 4upx solid #C8C8C8;
	}
</style>
